package maple.core;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.logging.Level;

import jade.wrapper.StaleProxyException;

public class Dummy extends MapleAgent
{
	private BufferedReader _reader;

	public Dummy()
	{
		super();

		_reader = new BufferedReader( new InputStreamReader( System.in ) );
	}

	protected void takeDown()
	{
		try
		{
			if( _reader != null )
			{
				_reader.close();
			}
		}
		catch( IOException e )
		{
			_logger.log( Level.WARNING, "", e );
		}

		try
		{
			getContainerController().kill();
		}
		catch( StaleProxyException e )
		{
			_logger.log( Level.WARNING, "", e );
		}
	}

	protected boolean distribute()
	{
		try
		{
			String line = _reader.readLine();
			if( line != null )
			{
				if( line.equals( "exit" ) )
				{
					doDelete();
				}
			}
		}
		catch( IOException e )
		{
			_logger.log( Level.WARNING, "", e );
		}
		return true;
	}
}
